1
|
|
|
// Type definitions for wavefile 11.0 |
2
|
|
|
// Project: https://github.com/rochars/wavefile |
3
|
|
|
// Definitions by: Rafael da Silva Rocha <https://github.com/rochars> |
4
|
|
|
// Definitions: https://github.com/rochars/wavefile |
5
|
|
|
|
6
|
|
|
export = wavefile; |
7
|
|
|
|
8
|
|
|
declare module wavefile { |
9
|
|
|
|
10
|
|
|
class WaveFile { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The bit depth code according to the samples. |
14
|
|
|
* @type {string} |
15
|
|
|
*/ |
16
|
|
|
bitDepth: string; |
17
|
|
|
/** |
18
|
|
|
* The container identifier. |
19
|
|
|
* 'RIFF', 'RIFX' and 'RF64' are supported. |
20
|
|
|
* @type {string} |
21
|
|
|
*/ |
22
|
|
|
container: string; |
23
|
|
|
/** |
24
|
|
|
* @type {number} |
25
|
|
|
*/ |
26
|
|
|
chunkSize: number; |
27
|
|
|
/** |
28
|
|
|
* The format. |
29
|
|
|
* Always 'WAVE'. |
30
|
|
|
* @type {string} |
31
|
|
|
*/ |
32
|
|
|
format: string; |
33
|
|
|
/** |
34
|
|
|
* The data of the 'fmt' chunk. |
35
|
|
|
* @type {!Object<string, *>} |
36
|
|
|
*/ |
37
|
|
|
fmt: object; |
38
|
|
|
/** |
39
|
|
|
* The data of the 'fact' chunk. |
40
|
|
|
* @type {!Object<string, *>} |
41
|
|
|
*/ |
42
|
|
|
fact: object; |
43
|
|
|
/** |
44
|
|
|
* The data of the 'cue ' chunk. |
45
|
|
|
* @type {!Object<string, *>} |
46
|
|
|
*/ |
47
|
|
|
cue: object; |
48
|
|
|
/** |
49
|
|
|
* The data of the 'smpl' chunk. |
50
|
|
|
* @type {!Object<string, *>} |
51
|
|
|
*/ |
52
|
|
|
smpl: object; |
53
|
|
|
/** |
54
|
|
|
* The data of the 'bext' chunk. |
55
|
|
|
* @type {!Object<string, *>} |
56
|
|
|
*/ |
57
|
|
|
bext: object; |
58
|
|
|
/** |
59
|
|
|
* The data of the 'iXML' chunk. |
60
|
|
|
* @type {!Object<string, *>} |
61
|
|
|
*/ |
62
|
|
|
iXML: object; |
63
|
|
|
/** |
64
|
|
|
* The data of the 'ds64' chunk. |
65
|
|
|
* Used only with RF64 files. |
66
|
|
|
* @type {!Object<string, *>} |
67
|
|
|
*/ |
68
|
|
|
ds64: object; |
69
|
|
|
/** |
70
|
|
|
* The data of the 'data' chunk. |
71
|
|
|
* @type {!Object<string, *>} |
72
|
|
|
*/ |
73
|
|
|
data: object; |
74
|
|
|
/** |
75
|
|
|
* The data of the 'LIST' chunks. |
76
|
|
|
* Each item in this list look like this: |
77
|
|
|
* { |
78
|
|
|
* chunkId: '', |
79
|
|
|
* chunkSize: 0, |
80
|
|
|
* format: '', |
81
|
|
|
* subChunks: [] |
82
|
|
|
* } |
83
|
|
|
* @type {!Array<!Object>} |
84
|
|
|
*/ |
85
|
|
|
LIST: object[]; |
86
|
|
|
/** |
87
|
|
|
* The data of the 'junk' chunk. |
88
|
|
|
* @type {!Object<string, *>} |
89
|
|
|
*/ |
90
|
|
|
junk: object; |
91
|
|
|
/** |
92
|
|
|
* The data of the '_PMX' chunk. |
93
|
|
|
* @type {!Object<string, *>} |
94
|
|
|
*/ |
95
|
|
|
_PMX: object; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param {Uint8Array=} [wavBuffer=null] A wave file buffer. |
99
|
|
|
* @throws {Error} If no 'RIFF' chunk is found. |
100
|
|
|
* @throws {Error} If no 'fmt ' chunk is found. |
101
|
|
|
* @throws {Error} If no 'data' chunk is found. |
102
|
|
|
*/ |
103
|
|
|
constructor(wavBuffer?: Uint8Array); |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Return the samples packed in a Float64Array. |
107
|
|
|
* @param {boolean=} [interleaved=false] True to return interleaved samples, |
108
|
|
|
* false to return the samples de-interleaved. |
109
|
|
|
* @param {Function=} [OutputObject=Float64Array] The sample container. |
110
|
|
|
* @return {!(Array|TypedArray)} the samples. |
111
|
|
|
*/ |
112
|
|
|
getSamples(interleaved?:boolean, OutputObject?: Function): Float64Array; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return the sample at a given index. |
116
|
|
|
* @param {number} index The sample index. |
117
|
|
|
* @return {number} The sample. |
118
|
|
|
* @throws {Error} If the sample index is off range. |
119
|
|
|
*/ |
120
|
|
|
getSample(index: number): number; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Set the sample at a given index. |
124
|
|
|
* @param {number} index The sample index. |
125
|
|
|
* @param {number} sample The sample. |
126
|
|
|
* @throws {Error} If the sample index is off range. |
127
|
|
|
*/ |
128
|
|
|
setSample(index: number, sample: number): void; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set up the WaveFileCreator object based on the arguments passed. |
132
|
|
|
* Existing chunks are reset. |
133
|
|
|
* @param {number} numChannels The number of channels. |
134
|
|
|
* @param {number} sampleRate The sample rate. |
135
|
|
|
* Integers like 8000, 44100, 48000, 96000, 192000. |
136
|
|
|
* @param {string} bitDepthCode The audio bit depth code. |
137
|
|
|
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64' |
138
|
|
|
* or any value between '8' and '32' (like '12'). |
139
|
|
|
* @param {!(Array|TypedArray)} samples The samples. |
140
|
|
|
* @param {Object=} options Optional. Used to force the container |
141
|
|
|
* as RIFX with {'container': 'RIFX'} |
142
|
|
|
* @throws {Error} If any argument does not meet the criteria. |
143
|
|
|
*/ |
144
|
|
|
fromScratch( |
145
|
|
|
numChannels: number, |
146
|
|
|
sampleRate: number, |
147
|
|
|
bitDepthCode: string, |
148
|
|
|
samples: Array<number>|Array<Array<number>>|ArrayLike<any>|Array<ArrayLike<any>>, |
149
|
|
|
options?: object): void; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set up the WaveFileParser object from a byte buffer. |
153
|
|
|
* @param {!Uint8Array} wavBuffer The buffer. |
154
|
|
|
* @param {boolean=} [samples=true] True if the samples should be loaded. |
155
|
|
|
* @throws {Error} If container is not RIFF, RIFX or RF64. |
156
|
|
|
* @throws {Error} If format is not WAVE. |
157
|
|
|
* @throws {Error} If no 'fmt ' chunk is found. |
158
|
|
|
* @throws {Error} If no 'data' chunk is found. |
159
|
|
|
*/ |
160
|
|
|
fromBuffer(bytes: Uint8Array, samples?:boolean): void; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Return a byte buffer representig the WaveFileParser object as a .wav file. |
164
|
|
|
* The return value of this method can be written straight to disk. |
165
|
|
|
* @return {!Uint8Array} A wav file. |
166
|
|
|
* @throws {Error} If bit depth is invalid. |
167
|
|
|
* @throws {Error} If the number of channels is invalid. |
168
|
|
|
* @throws {Error} If the sample rate is invalid. |
169
|
|
|
*/ |
170
|
|
|
toBuffer(): Uint8Array; |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Use a .wav file encoded as a base64 string to load the WaveFile object. |
174
|
|
|
* @param {string} base64String A .wav file as a base64 string. |
175
|
|
|
* @throws {Error} If any property of the object appears invalid. |
176
|
|
|
*/ |
177
|
|
|
fromBase64(base64String: string): void; |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Return a base64 string representig the WaveFile object as a .wav file. |
181
|
|
|
* @return {string} A .wav file as a base64 string. |
182
|
|
|
* @throws {Error} If any property of the object appears invalid. |
183
|
|
|
*/ |
184
|
|
|
toBase64(): string; |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Return a DataURI string representig the WaveFile object as a .wav file. |
188
|
|
|
* The return of this method can be used to load the audio in browsers. |
189
|
|
|
* @return {string} A .wav file as a DataURI. |
190
|
|
|
* @throws {Error} If any property of the object appears invalid. |
191
|
|
|
*/ |
192
|
|
|
toDataURI(): string; |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Use a .wav file encoded as a DataURI to load the WaveFile object. |
196
|
|
|
* @param {string} dataURI A .wav file as DataURI. |
197
|
|
|
* @throws {Error} If any property of the object appears invalid. |
198
|
|
|
*/ |
199
|
|
|
fromDataURI(dataURI: string): void; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Force a file as RIFF. |
203
|
|
|
*/ |
204
|
|
|
toRIFF(): void; |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Force a file as RIFX. |
208
|
|
|
*/ |
209
|
|
|
toRIFX(): void; |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Change the bit depth of the samples. |
213
|
|
|
* @param {string} newBitDepth The new bit depth of the samples. |
214
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats) |
215
|
|
|
* @param {boolean=} [changeResolution=true] A boolean indicating if the |
216
|
|
|
* resolution of samples should be actually changed or not. |
217
|
|
|
* @throws {Error} If the bit depth is not valid. |
218
|
|
|
*/ |
219
|
|
|
toBitDepth(newBitDepth: string, changeResolution?: boolean): void; |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Convert the sample rate of the file. |
223
|
|
|
* @param {number} sampleRate The target sample rate. |
224
|
|
|
* @param {Object=} options The extra configuration, if needed. |
225
|
|
|
*/ |
226
|
|
|
toSampleRate(samples: number, options?:object): void; |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Encode a 16-bit wave file as 4-bit IMA ADPCM. |
230
|
|
|
* @throws {Error} If sample rate is not 8000. |
231
|
|
|
* @throws {Error} If number of channels is not 1. |
232
|
|
|
*/ |
233
|
|
|
toIMAADPCM(): void; |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file. |
237
|
|
|
* @param {string=} [bitDepthCode='16'] The new bit depth of the samples. |
238
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats). |
239
|
|
|
*/ |
240
|
|
|
fromIMAADPCM(bitDepthCode?: string): void; |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Encode a 16-bit wave file as 8-bit A-Law. |
244
|
|
|
*/ |
245
|
|
|
toALaw(): void; |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Decode a 8-bit A-Law wave file into a 16-bit wave file. |
249
|
|
|
* @param {string=} [bitDepthCode='16'] The new bit depth of the samples. |
250
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats). |
251
|
|
|
*/ |
252
|
|
|
fromALaw(bitDepthCode?: string): void; |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Encode 16-bit wave file as 8-bit mu-Law. |
256
|
|
|
*/ |
257
|
|
|
toMuLaw(): void; |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Decode a 8-bit mu-Law wave file into a 16-bit wave file. |
261
|
|
|
* @param {string=} [bitDepthCode='16'] The new bit depth of the samples. |
262
|
|
|
* One of '8' ... '32' (integers), '32f' or '64' (floats). |
263
|
|
|
*/ |
264
|
|
|
fromMuLaw(bitDepthCode?: string): void; |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Write a RIFF tag in the INFO chunk. If the tag do not exist, |
268
|
|
|
* then it is created. It if exists, it is overwritten. |
269
|
|
|
* @param {string} tag The tag name. |
270
|
|
|
* @param {string} value The tag value. |
271
|
|
|
* @throws {Error} If the tag name is not valid. |
272
|
|
|
*/ |
273
|
|
|
setTag(tag: string, value: string): void; |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Return the value of a RIFF tag in the INFO chunk. |
277
|
|
|
* @param {string} tag The tag name. |
278
|
|
|
* @return {?string} The value if the tag is found, null otherwise. |
279
|
|
|
*/ |
280
|
|
|
getTag(tag: string): string|null; |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Return a Object<tag, value> with the RIFF tags in the file. |
284
|
|
|
* @return {!Object<string, string>} The file tags. |
285
|
|
|
*/ |
286
|
|
|
listTags(): object; |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Remove a RIFF tag in the INFO chunk. |
290
|
|
|
* @param {string} tag The tag name. |
291
|
|
|
* @return {boolean} True if a tag was deleted. |
292
|
|
|
*/ |
293
|
|
|
deleteTag(tag: string): boolean; |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Create a cue point in the wave file. |
297
|
|
|
* @param {!Object<string, *>} pointData The data of the cue point. |
298
|
|
|
*/ |
299
|
|
|
setCuePoint(pointData: object): void; |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Remove a cue point from a wave file. |
303
|
|
|
* @param {number} index the index of the point. First is 1, |
304
|
|
|
* second is 2, and so on. |
305
|
|
|
*/ |
306
|
|
|
deleteCuePoint(index: number): void; |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Return an array with all cue points in the file, in the order they appear |
310
|
|
|
* in the file. |
311
|
|
|
* Objects representing cue points/regions look like this: |
312
|
|
|
* { |
313
|
|
|
* position: 500, // the position in milliseconds |
314
|
|
|
* label: 'cue marker 1', |
315
|
|
|
* end: 1500, // the end position in milliseconds |
316
|
|
|
* dwName: 1, |
317
|
|
|
* dwPosition: 0, |
318
|
|
|
* fccChunk: 'data', |
319
|
|
|
* dwChunkStart: 0, |
320
|
|
|
* dwBlockStart: 0, |
321
|
|
|
* dwSampleOffset: 22050, // the position as a sample offset |
322
|
|
|
* dwSampleLength: 3646827, // the region length as a sample count |
323
|
|
|
* dwPurposeID: 544106354, |
324
|
|
|
* dwCountry: 0, |
325
|
|
|
* dwLanguage: 0, |
326
|
|
|
* dwDialect: 0, |
327
|
|
|
* dwCodePage: 0, |
328
|
|
|
* } |
329
|
|
|
* @return {!Array<Object>} |
330
|
|
|
*/ |
331
|
|
|
listCuePoints(): Array<object>; |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Update the label of a cue point. |
335
|
|
|
* @param {number} pointIndex The ID of the cue point. |
336
|
|
|
* @param {string} label The new text for the label. |
337
|
|
|
*/ |
338
|
|
|
updateLabel(pointIndex: number, label: string): void; |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Set the value of the iXML chunk. |
342
|
|
|
* @param {string} iXMLValue The value for the iXML chunk. |
343
|
|
|
* @throws {TypeError} If the value is not a string. |
344
|
|
|
*/ |
345
|
|
|
setiXML(iXMLValue: string): void; |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Return the value of the iXML chunk. |
349
|
|
|
* @return {string} The contents of the iXML chunk. |
350
|
|
|
*/ |
351
|
|
|
getiXML(): string; |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Set the value of the _PMX chunk. |
355
|
|
|
* @param {string} _PMXValue The value for the _PMX chunk. |
356
|
|
|
* @throws {TypeError} If the value is not a string. |
357
|
|
|
*/ |
358
|
|
|
set_PMX(_PMXValue: string): void; |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Get the value of the _PMX chunk. |
362
|
|
|
* @return {string} The contents of the _PMX chunk. |
363
|
|
|
*/ |
364
|
|
|
get_PMX(): string; |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|